//
//  DDRTSelectedManager.m
//  DDRichTextDemo
//
//  Created by 张小伟 on 2021/9/19.
//

#import "DDRTSelectedManager.h"
#import "DDRTGroupMemberModel.h"
#import <UIKit/UIKit.h>

@implementation DDRTSelectedManager

static DDRTSelectedManager *_selectedManager = nil;

-(instancetype)init {
    if (self = [super init]) {
        
    }
    return self;
}

+(instancetype)shareSelectedGroupManagerInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        _selectedManager = [[DDRTSelectedManager alloc] init];
    });
    return _selectedManager;
}

-(void)initAllDatas {
    
    [self.dataArr removeAllObjects];
    for (int index = 0; index < 5; index ++) {
        DDRTGroupMemberModel *model = [[DDRTGroupMemberModel alloc] init];
        model.personName = [NSString stringWithFormat: @"张三%02d",index];
        model.personPhone = [NSString stringWithFormat: @"157333312%02d",index];
        model.isSelected = NO;
        model.isClick = NO;
        [self.dataArr addObject:model];
    }
    
}

// 更新某一行选中状态
-(NSMutableArray *)updateItemManager:(NSIndexPath *)indexPath {
    if (self.dataArr.count) {
        if (indexPath.row < self.dataArr.count) {
            DDRTGroupMemberModel *itemModel = self.dataArr[indexPath.row];
            itemModel.isSelected = !itemModel.isSelected;
            return self.dataArr;
        }

    }
    return nil;
}




// 遍历到所有选中的数据
-(NSMutableArray *)getAllSelectedDatas {
    [self.selectedArr removeAllObjects];
    if (self.dataArr.count) {
        for (DDRTGroupMemberModel *itemModel in self.dataArr) {
            if (itemModel.isSelected) {
                [self.selectedArr addObject:itemModel];
            }
            
        }
        return self.selectedArr;
    }
    return nil;
}


-(NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

-(NSMutableArray *)selectedArr {
    if (!_selectedArr) {
        _selectedArr = [NSMutableArray array];
    }
    return _selectedArr;
}

@end
